package ModelLayer;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
 * Write a description of class Loan here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Loan
{  
    private long idD; //DVD's id
    private long idP; //person's id
    private Date borrowDate;
    private Copy copy; 
    private int  daysToBorrow;
    
    private static final long DAY = 24*60*60*1000; // 1 day in milliseconds
    private static final SimpleDateFormat ft = new SimpleDateFormat("yyyy.MM.dd 'at' hh:mm:ss");
    
    
    public Loan(long idD,long idP, int daysToBorrow, Copy copy)
    {
        this.idD = idD;
        this.idP = idP;
        this.daysToBorrow = daysToBorrow;
        this.copy = copy;
        borrowDate = new Date();       
    }
    
    
    public int getRemainingDays()
    {
        int diffDays = (int)( ( (new Date()).getTime() - borrowDate.getTime() ) / DAY );
        diffDays = daysToBorrow - diffDays;
        
        if(copy.getReturned()==true) daysToBorrow = 0;
        
        return diffDays;
    }
    
    
    // GET Methods
    public String getBorrowDate()    { return ft.format(borrowDate).toString(); }
    public long   getIDPerson()      { return idP; }
    public long   getIDDvd()         { return idD; }
    public Copy   getCopy()          { return copy; }
    public int    getDaysToBorrow()  { return daysToBorrow; }
}
